package com.nulldev.util.web.HttpServer3.extensions.flexiProxy.internal;

import java.io.ByteArrayInputStream;
import java.util.Map;

import com.nulldev.util.data.Charsets.CharsetUtil;
import com.nulldev.util.io.file.FileUtil;
import com.nulldev.util.web.HttpServer3.Response;
import com.nulldev.util.web.HttpServer3.extensions.flexiProxy.FlexiProxyHandler;

public class FlexiProxyInternalDebugHandler implements FlexiProxyHandler {

	private static final String PROXY_PAGE_HTML = FileUtil.getResourceAsString(FlexiProxyInternalDebugHandler.class, "flexi_proxy_page.html");

	@Override
	public Response overrideResponse(final String url, final Map<String, String> headers) {
		final String str = PROXY_PAGE_HTML.replace("${FlexiProxy.rules.length}", "0").replace("${FlexiProxy.handlers.length}", "0");
		final byte[] data = str.getBytes(CharsetUtil.UTF_8);
		return new Response(200, new ByteArrayInputStream(data));
	}

	@Override
	public FlexiProxyHandlerType type() {
		return FlexiProxyHandlerType.TYPE_RESPONSE_OVERRIDER;
	}
}
